#!/bin/sh

make clean;
make;

if [ ! -d "task3" ]; then
	mkdir task3
fi

rm -f task3/output_fcfs_mm3
rm -f task3/output_fcfs_mg3
rm -f task3/output_sjf_mm3
rm -f task3/output_sjf_mg3

echo "fcfs mm3"
for lambda in 0.0001 0.0002 0.0003 0.0004 0.0005 0.0006 0.0007 0.0008 0.0009
do
    ./proj3 $lambda 50000 0 0 1 >> task3/output_fcfs_mm3
done

echo "fcfs mg3"
for lambda in 0.0001 0.0002 0.0003 0.0004 0.0005 0.0006 0.0007 0.0008 0.0009
do
    ./proj3 $lambda 50000 0 1 1 >> task3/output_fcfs_mg3
done

echo "sjf mm3"
for lambda in 0.0001 0.0002 0.0003 0.0004 0.0005 0.0006 0.0007 0.0008 0.0009
do
    ./proj3 $lambda 50000 1 0 1 >> task3/output_sjf_mm3
done

echo "sjf mg3"
for lambda in 0.0001 0.0002 0.0003 0.0004 0.0005 0.0006 0.0007 0.0008 0.0009
do
    ./proj3 $lambda 50000 1 1 1 >> task3/output_sjf_mg3
done

grep 'Average system time =' task3/output_fcfs_mm3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' > task3/system_fcfs_mm3

grep 'Average system time =' task3/output_fcfs_mg3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' > task3/system_fcfs_mg3

grep 'Average system time =' task3/output_sjf_mm3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' > task3/system_sjf_mm3

grep 'Average system time =' task3/output_sjf_mg3 | egrep -o "[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"| awk '{ if (NR%3) printf("%s ", $0); else printf("%s\n", $0);}' > task3/system_sjf_mg3

echo "done"
